import Vue from 'vue'
import App from './App.vue'
import router from './router'
/* 导入字体图标 */
import './assets/fonts/iconfont.css'
/* 导入全局样式表 */
import './assets/css/global.css'
/* import tree table plgin */
import TreeTable from 'vue-table-with-tree-grid'
/* import vue quill editor  */
import VueQuillEditor from 'vue-quill-editor'

/* import NProgress */
import NProgress from 'nprogress'

/* Config axios for use */
import axios from 'axios'
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/' // base url
axios.interceptors.request.use(request => { // request interceptor
  /* show nprogress bar */
  NProgress.start()
  /* auto add token for request object */
  request.headers.Authorization = window.sessionStorage.getItem('token')
  return request
})
axios.interceptors.response.use(response => { // response interceptor
  /* close nprogress bar */
  NProgress.done()
  return response.data
}, error => {
  return Promise.reject(error)
})
Vue.prototype.$http = axios

Vue.config.productionTip = false

Vue.component('tree-table', TreeTable)
Vue.use(VueQuillEditor)
/* config global date filter */
Vue.filter('dateFormat', function (originVal) {
  const dt = new Date(originVal)
  const year = dt.getFullYear()
  const month = (dt.getMonth() + 1 + '').padStart(2, '0')
  const day = (dt.getDate() + '').padStart(2, 0)

  const hour = (dt.getHours() + '').padStart(2, 0)
  const minute = (dt.getMinutes() + '').padStart(2, 0)
  const second = (dt.getMinutes() + '').padStart(2, 0)

  return `${year}-${month}-${day} ${hour}:${minute}:${second}`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

/* msg is message alias */
Vue.prototype.$msg = Vue.prototype.$message
